package com.iflytek.hive.step2amountgoods;


import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class AmountGoodsMapper extends Mapper<LongWritable, Text, Text, DoubleWritable> {

    private final Text keyOut = new Text();
    private final DoubleWritable valueOut = new DoubleWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 将行文本数据切分
        String[] fields = value.toString().split(",");
        // 获取年+商品
        String goods = fields[0].substring(0,4)+","+fields[4];
        // 获取销售额
        String amount = fields[7];
        keyOut.set(goods);
        valueOut.set(Double.valueOf(amount));
        context.write(keyOut, valueOut);
    }

}
